<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row >
          <a-col :md="8" :sm="12">
            <a-form-item :label="$t('key.xh')" :labelCol="{span: 7, offset: 1}" :wrapperCol="{span: 15, offset: 1}">
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="12">
            <a-form-item :label="$t('key.name')" :labelCol="{span: 7, offset: 1}" :wrapperCol="{span: 15, offset: 1}">
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="advanced ? 8 : 6" :sm="12">
              <a-form-item :label="$t('key.yx')" :labelCol="{span: 7, offset: 1}" :wrapperCol="{span: 15, offset: 1}">
                <a-select allowClear v-model="queryParam.kcyx" @change="yxChange" :filterOption="filterOption">
                  <a-select-option v-for="(i, index) in selectMenu.yx" :key="index" :value="i.dwh">{{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item :label="$t('key.kcmc')" :labelCol="{span: 7, offset: 1}" :wrapperCol="{span: 15, offset: 1}">
                <a-select v-model="queryParam.kcdm" @change="kcChange" showSearch :filterOption="filterOption">
                  <a-spin v-if="kcLoading" slot="notFoundContent" size="small"/>
                  <a-select-option v-for="(i, index) in selectMenu.courseList" :key="index" :value="i.kch">{{ i.kcmc + '-' + i.kch }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item label="修课状态" :labelCol="{span: 7, offset: 1}" :wrapperCol="{span: 15, offset: 1}">
                <a-select allowClear v-model="queryParam.ksnj">
                  <a-select-option v-for="i in TYPE0326" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>

          <a-col :md="!advanced && 8 || 24" :sm="12">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">{{ $t('button.query') }}</a-button>
              <a-button type="primary" @click="handleSlow" style="margin:0 10px">缓考设置</a-button>
              <!-- <a-button style="margin: 0 10px" @click="() => queryParam = {}">{{ $t('button.reset') }}</a-button> -->
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? $t('button.collapse') : $t('button.expand') }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    
    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        rowKey="xsxh"
        :columns="columns"
        :data="loadData"
        :alert="{show: false}"
        :pagination="{ pageSize: 10 }"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
      </s-table>
    </a-card>
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'

export default {
  name: 'slow-setting',
  data() {
    return {
      form: this.$form.createForm(this),
      selectMenu: {},
      kcLoading: false,
      advanced: true,
      queryParam: {},
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'xsxh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '院系',
          dataIndex: ''
        },
        {
          title: '专业',
          dataIndex: ''
        },
        {
          title: '课程代码',
          dataIndex: ''
        },
        {
          title: '课程名称',
          dataIndex: 'kcmc'
        },
        {
          title: '课程类型',
          dataIndex: ''
        },
        {
          title: '修课状态',
          dataIndex: ''
        }
      ],
      loadData: parameter => {
        // parameter.pageNum = parameter.pageNo
        // let params = Object.assign(this.queryParam, parameter)
        // return this.$api.cultivate.kccjXsList(params).then(res => {
        //   console.log(res)
        //   return {
        //     data: res.data.rows,
        //     pageNo: parameter.pageNo,
        //     pageSize: parameter.pageSize,
        //     totalPage: Math.ceil(res.data.total / parameter.pageSize),
        //     totalCount: res.data.total
        //   }
        // })
      },
    }
  },
  components: { STable },
  computed: {
    ...mapState({
      TYPE0326: state => state.app['TYPE0326'], // 修课状态
    })
  },
  created () {
    this.initSelectMenu()
    this.$store.dispatch('app/setDictionary', 'TYPE0326')
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$nextTick(() => {
        this.$set(this.queryParam, 'kcdm', '')
        this.form.setFieldsValue({kcbm: ''})
        this.$set(this.selectMenu, 'courseList', [])
        if (code) {
          this.kcLoading = true
          this.$api.cultivate.courseAll({kcssyxm: code}).then(res => {
            this.$set(this.selectMenu, 'courseList', res.data)
          }).finally(() => {
            this.kcLoading = false
          })
        } else {
          this.$set(this.selectMenu, 'courseList', [])
        }
      })
    },
    kcChange (kch) {
      this.$nextTick(() => {
        let kc = this.selectMenu.courseList.find(kc => {
          return kc.kch === kch
        })
        this.form.setFieldsValue({
          xs: kc.zxs,
          xf: kc.xf
        })
      })
    },
    handleSlow() {
      console.log('huankao')
    }
  },
}
</script>


